# -*- coding: utf-8 -*-
from src.com.ydzy.util.base_util import BaserUtil
from src.com.ydzy.util.sql_util import MySQLUtils

db = MySQLUtils('192.168.8.234', 3306, 'root', 'root', 'audit_local')
base_client=BaserUtil()

def obtain_table_columns(table):
    columns = db.retrieve_columns(table=table)
    columns = [db.converter.snake_to_camel(item) for item in columns]
    return columns

def obtain_insert_sql(table):
    table_dict={}
    columns=obtain_table_columns(table)
    key=",".join(['?']*len(columns))
    table_dict[table]=[" , ".join(columns),key]
    return table_dict

def generate_insert_infos(tables):
    for table in tables:
        table_dict = obtain_insert_sql(table)
        for k, v in table_dict.items():
            print(v[0])
            print(v[1])
        print( "----------------------------------------------华丽的分割线----------------------------------------------")


def obtain_cond_sql(table):
    table_dict={}
    columns=obtain_table_columns(table)
    conds=[]
    c ="""/* and ? = '{?}' */"""
    for column in columns:
        conds.append(c.replace('?',column))
    table_dict[table]='\n'.join(conds)
    return table_dict


def generate_cond_infos(tables):
    for table in tables:
        table_dict = obtain_cond_sql(table)
        for k, v in table_dict.items():
            print(v)
        print( "----------------------------------------------华丽的分割线----------------------------------------------")


def obtain_update_sql(table):
    table_dict = {}
    columns = obtain_table_columns(table)
    conds = []
    c = """/*  ? = '{?}',  */"""
    for column in columns:
        conds.append(c.replace('?', column))
    table_dict[table] = '\n'.join(conds)
    return table_dict

def generate_update_infos(tables):
    for table in tables:
        table_dict = obtain_update_sql(table)
        for k, v in table_dict.items():
            print(v)
        print( "----------------------------------------------华丽的分割线----------------------------------------------")


def obtain_update_sql2(table):
    table_dict = {}
    columns = obtain_table_columns(table)
    conds = []
    for column in columns:
        conds.append(column+' =?')
    table_dict[table] = ','.join(conds)
    return table_dict


def generate_update_infos2(tables):
    for table in tables:
        table_dict = obtain_update_sql2(table)
        for k, v in table_dict.items():
            print(v)
        print( "----------------------------------------------华丽的分割线----------------------------------------------")


tables=['audit_service_config']
generate_insert_infos(tables)
generate_update_infos2(tables)
generate_cond_infos(tables)
generate_update_infos(tables)